package com.zimi.controller;


import com.zimi.model.SysOrgExtend;
import com.zimi.service.SysRoleUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 角色人员授权表 api
 *
 * @author lnintr
 * @since 2019-06-11
 */
@RestController
@RequestMapping("sys-role-user")
public class SysRoleUserApi {

    @Autowired
    private SysRoleUserService sysRoleUserService;

    @PostMapping("getOrgPostUser")
    public Object getOrgPostUser(int roleId) {
        Map map = sysRoleUserService.getUserTree(roleId);
        map.put("code", 0);
        return map;
    }

    @PostMapping("saveRoleUser")
    @ApiOperation("修改权限和机构信息")
    public Object saveRoleUser(SysOrgExtend sysOrgExtend) {
        sysRoleUserService.saveRoleUser(sysOrgExtend, 1);

        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("code", 0);
        return objectMap;
    }

    @PostMapping("deleteRoleUser")
    @ApiOperation("修改权限和机构信息")
    public Object deleteRoleUser(SysOrgExtend sysOrgExtend) {
        sysRoleUserService.saveRoleUser(sysOrgExtend, 2);

        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("code", 0);
        return objectMap;
    }
}
